﻿using System;

/// <summary>
/// 单例
/// </summary>
/// <typeparam name="T"></typeparam>
public class Singleton<T> : IDisposable where T : new()
{

    private static UnityEngine.Object obj = new UnityEngine.Object();
    private static T t;

    /// <summary>
    /// 引用
    /// </summary>
    /// <returns></returns>
    public static T Instance
    {
        get
        {
            if (t == null)
            {
                lock (obj)
                {
                    if (t == null)
                    {
                        t = new T();
                    }
                }
            }
            return t;
        }

    }

    /// <summary>
    /// 释放
    /// </summary>
    public virtual void Dispose()
    {

    }
}
